//
//  AppDelegate+Tool.m
//  AutoCare365
//
//  Created by SZJ on 2018/8/26.
//  Copyright © 2018年 SZJ. All rights reserved.
//

#import "AppDelegate+Tool.h"
#import "IQKeyboardManager.h"

#import "CC_BUG.h"
#import "Tool.h"
BaseViewController * _currentVC;

@implementation AppDelegate (Tool)

+(void)load{
    [super load];
    Method method1 = class_getInstanceMethod([self class], @selector(application:didFinishLaunchingWithOptions:));
    Method method2 = class_getInstanceMethod([self class], @selector(_application:didFinishLaunchingWithOptions:));

    method_exchangeImplementations(method1, method2);
}

- (BOOL)_application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    
    self.window = [[UIWindow alloc] initWithFrame:YYScreenBounds()];
    YYScreenWidth();
    YYScreenHeight();
    
    [IQKeyboardManager sharedManager].enable = YES;

    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;

    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;


    [self setTabbarCon];
    [self setNavCon];
    [self setTableVew];

    
    [CC_BUG beginBug:^(NSString *uuid, NSString *dsymUUID, NSString *reason) {

        return 1;
    }];
    



#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
    if(@available(iOS 13.0,*)){
        self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
    }
#endif
    

    
    [self addNotice];
    
    
    

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

    return [self _application:application didFinishLaunchingWithOptions:launchOptions];
}

-(void)setTabbarCon{
//
    [[UITabBarItem appearance] setTitleTextAttributes:  [NSDictionary dictionaryWithObjectsAndKeys:LC_RGB(153, 153, 153),NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:   [NSDictionary dictionaryWithObjectsAndKeys:LC_RGB(164, 0, 1),NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    
}

-(void)setNavCon{
    
//    [[UINavigationBar appearance] setShadowImage:[UIImage new]];
//    UIImageView * imageView = [[UIImageView  alloc] initWithImage:[UIImage imageNamed:@"navbg"]];
//    imageView.contentMode = UIViewContentModeScaleAspectFill;
//
//    [[UINavigationBar appearance] setBackgroundImage:imageView.image forBarMetrics:UIBarMetricsDefault];
//    UIImage *backGroundImage = [UIImage imageNamed:@"navbg"];
//        backGroundImage = [backGroundImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];
//        [[UINavigationBar appearance] setBackgroundImage:backGroundImage forBarMetrics:UIBarMetricsDefault];


     
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:TrueFontFloat(18)]}];
    [[UINavigationBar appearance] setTranslucent:NO];
    
      [UINavigationBar appearance].backgroundColor = [UIColor blackColor];
      [UINavigationBar appearance].barTintColor = [UIColor whiteColor];
        
}

- (void)setTableVew{
    if (@available(iOS 11.0, *)) {
        [UITableView appearance].estimatedRowHeight = 0;
        [UITableView appearance].estimatedSectionFooterHeight = 0;
        [UITableView appearance].estimatedSectionHeaderHeight = 0;
        [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    if (@available(iOS 11.0, *)) {
      
    }
}


- (void)addNotice{
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(recriveCurrentVC:) name:LC_CURRENTVC object:nil];
}



- (void)recriveCurrentVC:(NSNotification *)notifi{
    UIViewController *vc = notifi.object;
    [self setCurretVC:vc];
}

+(BaseViewController *)getCurrentVC{
    return objc_getAssociatedObject([UIApplication sharedApplication].delegate, @"currentVC");
}

-(void)setCurretVC:(UIViewController *)curretVC{
    objc_setAssociatedObject(self, @"currentVC", curretVC, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

+ (void)addSubview:(__kindof UIView *)view{
    if (CGPointEqualToPoint(view.frame.origin, CGPointZero)) {
        view.frame = YYScreenBounds();
    }
    [[UIApplication sharedApplication].keyWindow addSubview:view];
}

@end
